﻿using System;
using System.Collections;
using System.Web;
using System.Web.Caching;

namespace System.Data
{
	// Token: 0x02000006 RID: 6
	internal class NetCache : BaseCache
	{
		// Token: 0x0600002B RID: 43 RVA: 0x000024EC File Offset: 0x000006EC
		public override bool ContainsKey(string key)
		{
			bool result;
			if (HttpContext.Current == null)
			{
				result = (HttpRuntime.Cache.Get(key) != null);
			}
			else
			{
				result = (HttpContext.Current.Cache.Get(key) != null);
			}
			return result;
		}

		// Token: 0x0600002C RID: 44 RVA: 0x0000253C File Offset: 0x0000073C
		protected override void AddCache(string key, object target, int time, CacheDependency dependency)
		{
			if (HttpContext.Current == null)
			{
				this.AddCache_CS(key, target, time, dependency);
			}
			else
			{
				this.AddCache_BS(key, target, time, dependency);
			}
		}

		// Token: 0x0600002D RID: 45 RVA: 0x00002578 File Offset: 0x00000778
		private void AddCache_CS(string key, object target, int time, CacheDependency dependency)
		{
			if (dependency == null)
			{
				HttpRuntime.Cache.Insert(key, target, null, DateTime.Now.AddSeconds((double)time), Cache.NoSlidingExpiration);
			}
			else
			{
				HttpRuntime.Cache.Insert(key, target, dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
			}
		}

		// Token: 0x0600002E RID: 46 RVA: 0x000025D8 File Offset: 0x000007D8
		private void AddCache_BS(string key, object target, int time, CacheDependency dependency)
		{
			if (dependency == null)
			{
				HttpContext.Current.Cache.Insert(key, target, null, DateTime.Now.AddSeconds((double)time), Cache.NoSlidingExpiration);
			}
			else
			{
				HttpContext.Current.Cache.Insert(key, target, dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
			}
		}

		// Token: 0x0600002F RID: 47 RVA: 0x00002640 File Offset: 0x00000840
		protected override T GetCache<T>(string key)
		{
			T result;
			if (HttpContext.Current == null)
			{
				result = (HttpRuntime.Cache.Get(key) as T);
			}
			else
			{
				result = (HttpContext.Current.Cache.Get(key) as T);
			}
			return result;
		}

		// Token: 0x06000030 RID: 48 RVA: 0x00002694 File Offset: 0x00000894
		protected override void RemoveCache(string key)
		{
			if (HttpContext.Current == null)
			{
				HttpRuntime.Cache.Remove(key);
			}
			HttpContext.Current.Cache.Remove(key);
		}

		// Token: 0x06000031 RID: 49 RVA: 0x000026D0 File Offset: 0x000008D0
		public override void ClearAll()
		{
			if (HttpContext.Current == null)
			{
				IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator();
				while (enumerator.MoveNext())
				{
					HttpRuntime.Cache.Remove(enumerator.Key.ToString());
				}
			}
			else
			{
				IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator();
				while (enumerator.MoveNext())
				{
					HttpContext.Current.Cache.Remove(enumerator.Key.ToString());
				}
			}
		}
	}
}
